package com.wjm.api.FileRead;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Data:2022年07月10日
 * Author:wjm
 * Content: Writer(字符输出流抽象类) 和 FileWriter实现类
 *
 *
 *  Writer是字符输出流的顶级父类，FileWriter是它的实现类,FileWriter的直接父类是OutputStreamWriter(转换流)
 *
 *  Writer的常用方法
 *           void write(int c)  写入单个字符
 *           void write(char[] cbuf)  写入字符数组
 *           abstract void write(char[] cbuf, int off, int len) 写入字符数组的某一部分
 *           void write(String str)  写入字符串
 *           void write(String str, int off, int len)  写入字符串的某一部分
 *
 *           void flush()
 *           void close()
 *
 */
public class FileWriterDemo {
    public static void main(String[] args) throws IOException {
        //创建字符输出流对象
        FileWriter writer1 = new FileWriter(new File("e.txt"));
        //创建字符输出流对象
        FileWriter writer2 = new FileWriter("e.txt");

        //写入当个字符
        writer1.write(97);//a
        //写入字符数组
        char[] chars = {98,99};
        writer1.write(chars);

        //换行
        writer1.write("\r\n");

        //写入字符串
        writer1.write("陈婉婷猪猪");
        writer1.write("\r\n");
        //写入一段字符
        writer1.write("陈婉婷猪猪",3,2);

        //刷新，写入字符
        writer1.flush();
        //关闭流连接
        writer1.close();
    }
}
